$(function () {
    function orderInit() {
        function createEle(lang,id) {
            let no_orderEle = `<div class="no_order_container">
                                    <img src="../../img/no_order.png" alt="">
                                    <p>您还没有相关订单</p>
                                </div>`;
            let content_Ele = '';
            for(let value of lang){
                let btnEle = '';
                for(let i = 0;i<value.btn.length;i++){
                    btnEle += `<a class="${value.btn[i].className}" href="${value.btn[i].href}" external>${value.btn[i].text}</a>`
                }
                content_Ele += `<div class="content-block">
                                <div class="title_block clear">
                                    <p>${value.name}</p>
                                    <p>${value.status}</p>
                                </div>
                                <div class="list-block" style="margin: 0;">
                                    <ul class="list-container">
                                        <li class="item-content" style="padding-left: 0;">
                                        <a class="item-inner" href="../orderdetails/index.html" data-no-cache="true" style="padding: .5rem .5rem .5rem 0rem;display: block;color: #6d6d72;">
                                            <div class="item-title clear">
                                                <div class="img_container">
                                                    <img src="${value.img}" alt="">
                                                </div>
                                                <div class="content-box">
                                                    <p class="list-title">${value.title}</p>
                                                    <p class="list-content">${value.content}</p>
                                                </div>
                                            </div>
                                        </a>
                                        </li>
                                        <div class="list-footer clear">
                                            <p class="price_list">共<span>${value.num}</span>件商品 实付款：<span>${value.price}</span></p>
                                        </div>
                                        <div class="btn_container clear">${btnEle}</div>
                                    </ul>
                                </div>
                            </div>`
            }
            if(Array.isArray(lang)&&lang.length>0){
                $('#tab'+id)[0].innerHTML = content_Ele;
            }else{
                $('#tab'+id)[0].innerHTML = no_orderEle;
            }
        };
        require(['./order/unpaid/lang'],function (lang) {
            createEle(lang,1)
        });
        $('.tab-link').on('click',function (e) {
            let pay_state = e.target.innerText;
            switch (pay_state){
                case "未付款":
                    require(['./dist/scripts/order/unpaid/lang'],function (lang) {
                        createEle(lang,1)
                    });
                    break;
                case "已付款":
                    require(['./dist/scripts/order/already_paid/lang'],function (lang) {
                        createEle(lang,2)
                    });
                    break;
                case "已退款":
                    require(['./dist/scripts/order/refunded/lang'],function (lang) {
                        createEle(lang,3)
                    });
                    break;
                default:
                    require(['./dist/scripts/order/closed/lang'],function (lang) {
                        createEle(lang,4)
                    });
            }
        })
    };
    orderInit();
    $(document).on("pageInit", '#orderList',function(e, pageId, $page) {
        orderInit();
    });
    $(document).on("pageInit", '#orderDetails',function(e, pageId, $page) {
        require(['./dist/scripts/orderdetails/orderdetails'],function (exec) {
            exec();
        })
    });
})